import React, { Component, createRef } from "react";

class App extends Component {
  // ipt就是一个空的地址的指向
  ipt = createRef();
  ipt2 = createRef();

  handleClick = () => {
    // 可以通过this.ipt.current获取到input这个dom元素
    console.log(this.ipt.current.value);
  };

  fn = () => {
    console.log(this.ipt2.current.files);
  };

  render() {
    return (
      <>
        <h2>非受控组件</h2>
        {/* 非受控组件的默认值要用defaultValue属性 */}
        <input type="text" ref={this.ipt} defaultValue="abc" />
        <button onClick={this.handleClick}>btn</button>

        <hr />

        <input type="file" ref={this.ipt2} />
        <button onClick={this.fn}>提交</button>
      </>
    );
  }
}

export default App;
